home *** CD-ROM | disk | FTP | other *** search
- Here goes, I guess...
- Greeny #8 @6910
- Thu Dec 12 05:38:34 1991
- RANDOM MULTI-LINE QUOTES AT MENU PROMPTS
-
- GREENY01.MOD
- Version 1.00
-
- Here's a mod that will allow random quotes at each main menu and transfer
- menu prompt. It's mostly block read in, and unless you really want to you
- won't have to recompile your whole source code.
-
- To edit the entire quote list (add quotes to the list, delete any quote from
- the list, or view the entire list) type //quoteedit from the main menu, or
- hit the quote key (") when it's waiting for a caller. It will create and
- update a data file called RANQUOTE.DAT, in the gfiles directory.
-
- To install the mod, do this:
-
- 1) back up your source code.
-
- 2) You must prototype the three new functions. The easy way to do this
- is to stick them into the beginning of the file BBS.C. Right after the
- line #define modem_time 3.5 is a good place. The function prototypes look
- like this:
-
- void random_quote();
- char *get_random_quote();
- void thump();
-
- Just add them into your source code, each on a seperate line.
-
- 3) Now find the function "void main()". To do a search in Turbo C, or TC++,
- Hit Control-Q Control-F, and type in void main() on the line it gives you.
- Near the beginning of void main(), you'll find the following code. Add
- the line indicated. (== means this line is already there, ++ means add
- this line)
-
-
- == if ((sysstatus_expert & thisuser.sysstatus)==0)
- == printmenu(0);
- ==
- == nl();
- ++ thump(get_random_quote(),&abort);
- == nl();
- == tleft(1);
-
- 4) About one screen down from the last change you should see this. Add the
- four lines indicated.
-
- ==/**************************************************/
- == if (so()) {
- ++ if (strcmp(s,"QUOTEEDIT")==0) {
- ++ sysoplog("@ Ran QuoteEdit");
- ++ random_quote();
- ++ }
- == if (strcmp(s,"BOARDEDIT")==0) {
- == sysoplog("@ Ran Boardedit");
- == boardedit();
- == }
-
-
- 5) Next, search for the function "void dlmainmenu()" and insert the indicated
- line, near the beginning.
-
-
- == if ((sysstatus_expert & thisuser.sysstatus)==0)
- == printmenu(3);
- ==
- == nl();
- ++ thump(get_random_quote(),&abort);
- == nl();
- == tleft(1);
-
-
- 6) Now search for the function "void getcaller()" and add these three lines.
- (They're about three screens down from the beginning...)
-
-
- == switch(ch) {
- ++ case '\"':
- ++ if (ok_local()) random_quote();
- ++ break;
- == case '?':
- == if (ok_local()) {
-
-
- 7) Those are all the changes that need to be made to the existing code. Now
- we add some new functions. These can be block read in if you don't feel
- like typeing them. (To block read something in, hit Control-K Control-R,
- tell it the file name, and then hit Control-K Control-H to put the colors
- back to normal. Just block read in this entire mod at the end of BBS.C
- and delete all the lines before and after the functions. (Control-Y will
- delete the line your cursor is currently on.)
-
-
- /* BEGINNING OF BLOCK READ FOR GREENY'S RANDOM QUOTE MOD */
-
- void random_quote()
- {
-
- #define QUOTE_LINES 3
- #define QUOTE_SIZE ((80*QUOTE_LINES)+1)
-
- long int f,f1,i,i1,i42,offset;
- int done,abort;
- char s[QUOTE_SIZE],s1[100],ch,ch1;
-
- done=0;
- for(i=0; i<QUOTE_SIZE; i++) {
- s[i]=0;
- }
- i=0;
- do {
- abort=0;
- prt(5,"Random Quotes - A)dd, L)ist, D)elete, Q)uit :");
- ch=onek("QLAD");
- switch(ch) {
- case 'Q':
- done=1;
- break;
- case 'L':
- outstr("\x0c");
- nl();
- prt(2,"Random Quotes Available");
- nl();
- prt(2,"-----------------------");
- nl();
- strcpy(s1,syscfg.gfilesdir);
- strcat(s1,"RANQUOTE.DAT");
- if((f=open(s1,O_RDONLY))==-1) {
- close(f);
- prt(3, "There are no quotes available.");
- nl();
- break;
- }
- lseek(f,0L,SEEK_SET);
- i=filelength(f)/QUOTE_SIZE;
- if (i == 0) {
- nl();
- prt(3, "There are no quotes available.");
- nl();
- close(f);
- break;
- }
- for (i1=0,(i=filelength(f)/QUOTE_SIZE); i1<i; i1++)
- {
- lseek(f,((long) (i1*QUOTE_SIZE)),SEEK_SET);
- read(f,s,QUOTE_SIZE);
- sprintf(s1,"%04d:",i1+1);
- pla(s1,&abort);
- thump(s,&abort);
- if(abort) break;
- }
- nl();
- close(f);
- break;
- case 'A':
- nl();
- prt(2,"Enter Random Quote...");
- nl();
- sprintf(s1,"Enter Random quote, %d lines maximum",QUOTE_LINES);
- pl(s1);
- s1[0]=0;
- s[0]=0;
- nl();
- for (i=0; i<3; i++) {
- npr("%d:",i+1);
- mpl(77);
- inli(s+strlen(s),s1,77,1);
- if(s[0]==0) break;
- if(s[strlen(s)-1]=='\n') break;
- if(s[strlen(s)-1]==1) s[strlen(s)-1]=0;
- strcat(s,"\n");
- }
- if(s[0]==0) {
- nl();
- prt(3, "Aborted");
- nl();
- break;
- }
- strcpy(s1,syscfg.gfilesdir);
- strcat(s1,"RANQUOTE.DAT");
- f=open(s1,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
- if(filelength(f)) {
- lseek(f,-1L,SEEK_END);
- read(f,((void *)&ch1),1);
- if(ch1==26) lseek(f,-1L,SEEK_END);
- }
- s[QUOTE_SIZE-1]=0;
- write(f,(void *)s,QUOTE_SIZE);
- close(f);
- break;
- case 'D':
- prt(6,"Number of quote to delete : ");
- mpl(4);
- inputl(s,4);
- i42=atoi(s);
- if(i42<1) break;
- strcpy(s1,syscfg.gfilesdir);
- strcat(s1,"RANQUOTE.DAT");
- f=open(s1,O_RDWR | O_BINARY);
- if(f>-1) {
- i1=filelength(f);
- if(i42>i1/QUOTE_SIZE) {
- close(f);
- break;
- }
- i42--;
- lseek(f,(long) (i42 * QUOTE_SIZE), SEEK_SET);
- read(f,s,QUOTE_SIZE);
- nl();
- nl();
- thump(s,&abort);
- nl();
- prt(5,"Delete this Quote ?");
- if (yn()) {
- if(i42<(i1/QUOTE_SIZE)-1) {
- for(i=i42; i<(i1/QUOTE_SIZE)-1; i++) {
- lseek(f,(long) (QUOTE_SIZE * (i+1)),SEEK_SET);
- read(f,(void *)s,QUOTE_SIZE);
- lseek(f,(long) (QUOTE_SIZE * i),SEEK_SET);
- write(f,(void *)s,QUOTE_SIZE);
- }
- }
- chsize(f,(long) (i1-QUOTE_SIZE));
- pl("Quote deleted");
- }
- close(f);
- }
- break;
- }
- } while ((!done) && (!hangup));
- }
-
- char *get_random_quote()
- {
- long int f,i,i1;
- static char s1[QUOTE_SIZE];
- char s[100];
-
- s1[0]=0;
- strcpy(s,syscfg.gfilesdir);
- strcat(s,"RANQUOTE.DAT");
- if ((f=open(s,O_RDONLY))!=-1)
- {
- lseek(f,0L,SEEK_SET);
- i=filelength(f)/QUOTE_SIZE;
- if(i) {
- i1=random(i);
- lseek(f,(long) (i1 * QUOTE_SIZE),SEEK_SET);
- read(f,s1,QUOTE_SIZE);
- }
- close(f);
- }
- return s1;
- }
-
- void thump(char *s, int *abort)
- {
- int i=0,what=0;
- while(s[i]) {
- if(!(*abort)) {
- if(s[i]=='\n') nl();
- else outchr(s[i]);
- }
- checka(abort,& what);
- i++;
- }
- }
-
- /* END OF BLOCK READ FOR GREENY'S RANDOM QUOTE MOD */
-
- 8) Now save off the file by hitting F2, and compile it. (If you haven't
- figured out how to set up a decent project file, figure out how to do so
- and in the mean time drop to dos and use random's make file.)
-
- 9) Send me some email. I have an account as user #8 at WWIVnet node @6910.
-
- Until next time...
-
- 3(GREENY)0
-
- 9
- 9THE PROMISED LAND- Delran NJ 609-764-7144
- 86HOST OF SUB 42 - DEEP THOUGHT: THE INTERNATIONAL MENSA NET0
- 738400/ARQ/HST/HST/V32/V42/BIS